#!/bin/bash
###SHELLPACK preamble thpscale-bench 0

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam	--min-threads	THPSCALE_MIN_THREADS
###SHELLPACK parseargParam	--max-threads	THPSCALE_MAX_THREADS
###SHELLPACK parseargParam	--mapsize	THPSCALE_MAPSIZE
###SHELLPACK parseargParam	--madv-huge	THPSCALE_MADV_HUGEPAGE
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required thpscale-${VERSION}
###SHELLPACK init_complete

create_random_file $((THPSCALE_MAPSIZE+1048576*16)) $SHELLPACK_DATA/workfile

MADV_HUGEPAGE=0
if [ "$THPSCALE_MADV_HUGEPAGE" = "yes" ]; then
	MADV_HUGEPAGE=1
fi

###SHELLPACK threads_large_stride_begin $THPSCALE_MIN_THREADS $THPSCALE_MAX_THREADS
	echo Dropping cache to avoid distorting init timings
	echo 3 > /proc/sys/vm/drop_caches
	monitor_pre_hook $LOGDIR_RESULTS $NR_THREADS
	echo Starting $NR_THREADS/$THPSCALE_MAX_THREADS
	$TIME_CMD -o $LOGDIR_RESULTS/threads-${NR_THREADS}.time \
		./thpscale $NR_THREADS $THPSCALE_MAPSIZE $SHELLPACK_DATA/workfile $MADV_HUGEPAGE \
			> $LOGDIR_RESULTS/threads-${NR_THREADS}.log 2>&1
	monitor_post_hook $LOGDIR_RESULTS $NR_THREADS
	gzip $LOGDIR_RESULTS/threads-${NR_THREADS}.log
###SHELLPACK threads_stride_end
rm $SHELLPACK_DATA/workfile
exit $SHELLPACK_SUCCESS
